home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / database / randomfa / address.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-12-29  |  42.0 KB  |  1,319 lines

  1. VERSION 2.00
  2. Begin Form frmRecordEditor 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Random Access Address File Record Editor"
  5.    ClientHeight    =   5535
  6.    ClientLeft      =   1350
  7.    ClientTop       =   1800
  8.    ClientWidth     =   8505
  9.    ClipControls    =   0   'False
  10.    Height          =   6225
  11.    Icon            =   ADDRESS.FRX:0000
  12.    Left            =   1290
  13.    LinkTopic       =   "Form1"
  14.    ScaleHeight     =   5535
  15.    ScaleWidth      =   8505
  16.    Top             =   1170
  17.    Width           =   8625
  18.    Begin CommandButton cmdOption 
  19.       Caption         =   "Jumble Data"
  20.       Height          =   315
  21.       Index           =   10
  22.       Left            =   6870
  23.       TabIndex        =   42
  24.       TabStop         =   0   'False
  25.       Tag             =   "Jumble"
  26.       Top             =   4770
  27.       Width           =   1500
  28.    End
  29.    Begin CommandButton cmdOption 
  30.       Caption         =   "Find Deleted"
  31.       Height          =   315
  32.       Index           =   9
  33.       Left            =   5220
  34.       TabIndex        =   15
  35.       TabStop         =   0   'False
  36.       Tag             =   "FindDeleted"
  37.       Top             =   4770
  38.       Width           =   1500
  39.    End
  40.    Begin SSCheck chkSave 
  41.       Caption         =   "Show Save Message"
  42.       Height          =   255
  43.       Left            =   6240
  44.       TabIndex        =   41
  45.       TabStop         =   0   'False
  46.       Top             =   3900
  47.       Value           =   -1  'True
  48.       Width           =   2085
  49.    End
  50.    Begin TextBox txtData 
  51.       Height          =   285
  52.       Index           =   0
  53.       Left            =   1260
  54.       MaxLength       =   30
  55.       TabIndex        =   28
  56.       Tag             =   "AccountNumber"
  57.       Top             =   120
  58.       Width           =   1755
  59.    End
  60.    Begin CommandButton cmdOption 
  61.       Caption         =   "Open File"
  62.       Height          =   315
  63.       Index           =   5
  64.       Left            =   3510
  65.       TabIndex        =   18
  66.       TabStop         =   0   'False
  67.       Tag             =   "Open"
  68.       Top             =   5100
  69.       Width           =   1500
  70.    End
  71.    Begin ListBox lstResults 
  72.       Height          =   3735
  73.       Left            =   4590
  74.       Sorted          =   -1  'True
  75.       TabIndex        =   11
  76.       Top             =   90
  77.       Width           =   3735
  78.    End
  79.    Begin SSCommand cmdAbort 
  80.       Caption         =   "&Abort Random Generator"
  81.       Font3D          =   1  'Raised w/light shading
  82.       ForeColor       =   &H00FF0000&
  83.       Height          =   315
  84.       Left            =   3000
  85.       TabIndex        =   26
  86.       TabStop         =   0   'False
  87.       Top             =   3930
  88.       Visible         =   0   'False
  89.       Width           =   2325
  90.    End
  91.    Begin TextBox txtData 
  92.       Height          =   285
  93.       Index           =   11
  94.       Left            =   1275
  95.       MaxLength       =   15
  96.       TabIndex        =   10
  97.       Tag             =   "Status"
  98.       Top             =   3480
  99.       Width           =   450
  100.    End
  101.    Begin CommandButton cmdOption 
  102.       Caption         =   "Exit"
  103.       Height          =   315
  104.       Index           =   8
  105.       Left            =   6870
  106.       TabIndex        =   21
  107.       TabStop         =   0   'False
  108.       Tag             =   "Exit"
  109.       Top             =   5100
  110.       Width           =   1500
  111.    End
  112.    Begin TextBox txtData 
  113.       Height          =   285
  114.       Index           =   1
  115.       Left            =   1275
  116.       MaxLength       =   30
  117.       TabIndex        =   0
  118.       Tag             =   "Company"
  119.       Top             =   420
  120.       Width           =   3000
  121.    End
  122.    Begin TextBox txtData 
  123.       Height          =   285
  124.       Index           =   10
  125.       Left            =   1275
  126.       MaxLength       =   15
  127.       TabIndex        =   9
  128.       Tag             =   "EMail"
  129.       Top             =   3120
  130.       Width           =   1665
  131.    End
  132.    Begin TextBox txtData 
  133.       Height          =   285
  134.       Index           =   9
  135.       Left            =   1275
  136.       MaxLength       =   15
  137.       TabIndex        =   8
  138.       Tag             =   "Fax"
  139.       Top             =   2820
  140.       Width           =   1665
  141.    End
  142.    Begin TextBox txtData 
  143.       Height          =   285
  144.       Index           =   8
  145.       Left            =   1275
  146.       MaxLength       =   15
  147.       TabIndex        =   7
  148.       Tag             =   "Telephone"
  149.       Top             =   2520
  150.       Width           =   1665
  151.    End
  152.    Begin TextBox txtData 
  153.       Height          =   285
  154.       Index           =   7
  155.       Left            =   1275
  156.       MaxLength       =   15
  157.       TabIndex        =   6
  158.       Tag             =   "PostCode"
  159.       Top             =   2220
  160.       Width           =   1665
  161.    End
  162.    Begin TextBox txtData 
  163.       Height          =   285
  164.       Index           =   6
  165.       Left            =   1275
  166.       MaxLength       =   30
  167.       TabIndex        =   5
  168.       Tag             =   "Address3"
  169.       Top             =   1920
  170.       Width           =   3000
  171.    End
  172.    Begin TextBox txtData 
  173.       Height          =   285
  174.       Index           =   5
  175.       Left            =   1275
  176.       MaxLength       =   30
  177.       TabIndex        =   4
  178.       Tag             =   "Address2"
  179.       Top             =   1620
  180.       Width           =   3000
  181.    End
  182.    Begin TextBox txtData 
  183.       Height          =   285
  184.       Index           =   4
  185.       Left            =   1275
  186.       MaxLength       =   30
  187.       TabIndex        =   3
  188.       Tag             =   "Address1"
  189.       Top             =   1320
  190.       Width           =   3000
  191.    End
  192.    Begin TextBox txtData 
  193.       Height          =   285
  194.       Index           =   3
  195.       Left            =   1275
  196.       MaxLength       =   30
  197.       TabIndex        =   2
  198.       Tag             =   "Surname"
  199.       Top             =   1020
  200.       Width           =   3000
  201.    End
  202.    Begin TextBox txtData 
  203.       Height          =   285
  204.       Index           =   2
  205.       Left            =   1275
  206.       MaxLength       =   30
  207.       TabIndex        =   1
  208.       Tag             =   "Forename"
  209.       Top             =   720
  210.       Width           =   3000
  211.    End
  212.    Begin CommandButton cmdOption 
  213.       Caption         =   "Generate Random Data"
  214.       Height          =   315
  215.       Index           =   7
  216.       Left            =   3000
  217.       TabIndex        =   25
  218.       TabStop         =   0   'False
  219.       Tag             =   "Random"
  220.       Top             =   3930
  221.       Width           =   2325
  222.    End
  223.    Begin CommandButton cmdOption 
  224.       Caption         =   "Find Next"
  225.       Enabled         =   0   'False
  226.       Height          =   315
  227.       Index           =   4
  228.       Left            =   3510
  229.       TabIndex        =   14
  230.       TabStop         =   0   'False
  231.       Tag             =   "FindNext"
  232.       Top             =   4770
  233.       Width           =   1500
  234.    End
  235.    Begin SSCommand cmdMove 
  236.       Height          =   315
  237.       Index           =   0
  238.       Left            =   2460
  239.       Picture         =   ADDRESS.FRX:0302
  240.       TabIndex        =   24
  241.       TabStop         =   0   'False
  242.       Tag             =   "First"
  243.       Top             =   4380
  244.       Width           =   800
  245.    End
  246.    Begin SSCommand cmdMove 
  247.       Height          =   315
  248.       Index           =   1
  249.       Left            =   3300
  250.       Picture         =   ADDRESS.FRX:0460
  251.       TabIndex        =   23
  252.       TabStop         =   0   'False
  253.       Tag             =   "Previous"
  254.       Top             =   4380
  255.       Width           =   800
  256.    End
  257.    Begin SSCommand cmdMove 
  258.       Height          =   315
  259.       Index           =   2
  260.       Left            =   4140
  261.       Picture         =   ADDRESS.FRX:05BE
  262.       TabIndex        =   22
  263.       TabStop         =   0   'False
  264.       Tag             =   "Next"
  265.       Top             =   4380
  266.       Width           =   800
  267.    End
  268.    Begin SSCommand cmdMove 
  269.       Height          =   315
  270.       Index           =   3
  271.       Left            =   4980
  272.       Picture         =   ADDRESS.FRX:071C
  273.       TabIndex        =   20
  274.       TabStop         =   0   'False
  275.       Tag             =   "Last"
  276.       Top             =   4380
  277.       Width           =   800
  278.    End
  279.    Begin CommandButton cmdOption 
  280.       Caption         =   "Find Surname"
  281.       Height          =   315
  282.       Index           =   3
  283.       Left            =   1830
  284.       TabIndex        =   13
  285.       TabStop         =   0   'False
  286.       Tag             =   "FindString"
  287.       Top             =   4770
  288.       Width           =   1500
  289.    End
  290.    Begin CommandButton cmdOption 
  291.       Caption         =   "Find Record"
  292.       Height          =   315
  293.       Index           =   2
  294.       Left            =   150
  295.       TabIndex        =   12
  296.       TabStop         =   0   'False
  297.       Tag             =   "FindRecord"
  298.       Top             =   4770
  299.       Width           =   1500
  300.    End
  301.    Begin CommandButton cmdOption 
  302.       Caption         =   "Save Changes"
  303.       Height          =   315
  304.       Index           =   6
  305.       Left            =   5220
  306.       TabIndex        =   19
  307.       TabStop         =   0   'False
  308.       Tag             =   "Save"
  309.       Top             =   5100
  310.       Width           =   1500
  311.    End
  312.    Begin CommandButton cmdOption 
  313.       Caption         =   "Delete Record"
  314.       Height          =   315
  315.       Index           =   1
  316.       Left            =   1830
  317.       TabIndex        =   17
  318.       TabStop         =   0   'False
  319.       Tag             =   "Delete"
  320.       Top             =   5100
  321.       Width           =   1500
  322.    End
  323.    Begin CommandButton cmdOption 
  324.       Caption         =   "Add Record"
  325.       Height          =   315
  326.       Index           =   0
  327.       Left            =   150
  328.       TabIndex        =   16
  329.       TabStop         =   0   'False
  330.       Tag             =   "Add"
  331.       Top             =   5100
  332.       Width           =   1500
  333.    End
  334.    Begin Label lblData 
  335.       Alignment       =   1  'Right Justify
  336.       BackColor       =   &H00C0C0C0&
  337.       Caption         =   "Status"
  338.       Height          =   225
  339.       Index           =   11
  340.       Left            =   90
  341.       TabIndex        =   40
  342.       Top             =   3480
  343.       Width           =   1095
  344.    End
  345.    Begin Label lblData 
  346.       Alignment       =   1  'Right Justify
  347.       BackColor       =   &H00C0C0C0&
  348.       Caption         =   "EMail"
  349.       Height          =   225
  350.       Index           =   10
  351.       Left            =   90
  352.       TabIndex        =   39
  353.       Top             =   3180
  354.       Width           =   1095
  355.    End
  356.    Begin Label lblData 
  357.       Alignment       =   1  'Right Justify
  358.       BackColor       =   &H00C0C0C0&
  359.       Caption         =   "Fax"
  360.       Height          =   225
  361.       Index           =   9
  362.       Left            =   90
  363.       TabIndex        =   38
  364.       Top             =   2880
  365.       Width           =   1095
  366.    End
  367.    Begin Label lblData 
  368.       Alignment       =   1  'Right Justify
  369.       BackColor       =   &H00C0C0C0&
  370.       Caption         =   "Telephone"
  371.       Height          =   225
  372.       Index           =   8
  373.       Left            =   90
  374.       TabIndex        =   37
  375.       Top             =   2550
  376.       Width           =   1095
  377.    End
  378.    Begin Label lblData 
  379.       Alignment       =   1  'Right Justify
  380.       BackColor       =   &H00C0C0C0&
  381.       Caption         =   "Post Code"
  382.       Height          =   225
  383.       Index           =   7
  384.       Left            =   90
  385.       TabIndex        =   36
  386.       Top             =   2250
  387.       Width           =   1095
  388.    End
  389.    Begin Label lblData 
  390.       Alignment       =   1  'Right Justify
  391.       BackColor       =   &H00C0C0C0&
  392.       Caption         =   "Address3"
  393.       Height          =   225
  394.       Index           =   6
  395.       Left            =   90
  396.       TabIndex        =   35
  397.       Top             =   1950
  398.       Width           =   1095
  399.    End
  400.    Begin Label lblData 
  401.       Alignment       =   1  'Right Justify
  402.       BackColor       =   &H00C0C0C0&
  403.       Caption         =   "Address2"
  404.       Height          =   225
  405.       Index           =   5
  406.       Left            =   90
  407.       TabIndex        =   34
  408.       Top             =   1650
  409.       Width           =   1095
  410.    End
  411.    Begin Label lblData 
  412.       Alignment       =   1  'Right Justify
  413.       BackColor       =   &H00C0C0C0&
  414.       Caption         =   "Address1"
  415.       Height          =   225
  416.       Index           =   4
  417.       Left            =   90
  418.       TabIndex        =   33
  419.       Top             =   1350
  420.       Width           =   1095
  421.    End
  422.    Begin Label lblData 
  423.       Alignment       =   1  'Right Justify
  424.       BackColor       =   &H00C0C0C0&
  425.       Caption         =   "Surname"
  426.       Height          =   225
  427.       Index           =   3
  428.       Left            =   90
  429.       TabIndex        =   32
  430.       Top             =   1050
  431.       Width           =   1095
  432.    End
  433.    Begin Label lblData 
  434.       Alignment       =   1  'Right Justify
  435.       BackColor       =   &H00C0C0C0&
  436.       Caption         =   "Forename"
  437.       Height          =   225
  438.       Index           =   2
  439.       Left            =   90
  440.       TabIndex        =   31
  441.       Top             =   750
  442.       Width           =   1095
  443.    End
  444.    Begin Label lblData 
  445.       Alignment       =   1  'Right Justify
  446.       BackColor       =   &H00C0C0C0&
  447.       Caption         =   "Company"
  448.       Height          =   225
  449.       Index           =   1
  450.       Left            =   90
  451.       TabIndex        =   30
  452.       Top             =   450
  453.       Width           =   1095
  454.    End
  455.    Begin Label lblData 
  456.       Alignment       =   1  'Right Justify
  457.       BackColor       =   &H00C0C0C0&
  458.       Caption         =   "Account No"
  459.       Height          =   225
  460.       Index           =   0
  461.       Left            =   90
  462.       TabIndex        =   29
  463.       Top             =   150
  464.       Width           =   1095
  465.    End
  466.    Begin Label lblDeleted 
  467.       Alignment       =   2  'Center
  468.       BackColor       =   &H000000FF&
  469.       Caption         =   "<<< Deleted"
  470.       ForeColor       =   &H00FFFFFF&
  471.       Height          =   225
  472.       Left            =   1770
  473.       TabIndex        =   27
  474.       Top             =   3510
  475.       Visible         =   0   'False
  476.       Width           =   1305
  477.    End
  478.    Begin Menu mnuFile 
  479.       Caption         =   "&File"
  480.       Begin Menu mnuFileOpen 
  481.          Caption         =   "&Open"
  482.       End
  483.       Begin Menu mnuFileLine 
  484.          Caption         =   "-"
  485.       End
  486.       Begin Menu mnuFileExit 
  487.          Caption         =   "E&xit"
  488.       End
  489.    End
  490.    Begin Menu mnuEdit 
  491.       Caption         =   "&Edit"
  492.       Begin Menu mnuEditAdd 
  493.          Caption         =   "&Add Record"
  494.       End
  495.       Begin Menu mnuEditDelete 
  496.          Caption         =   "&Delete Record"
  497.       End
  498.       Begin Menu mnuEditSave 
  499.          Caption         =   "&Save Record"
  500.       End
  501.       Begin Menu mnuEditJumble 
  502.          Caption         =   "&Jumble Data"
  503.       End
  504.    End
  505.    Begin Menu mnuFind 
  506.       Caption         =   "Fin&d"
  507.       Begin Menu mnuFindRecord 
  508.          Caption         =   "Find &Record"
  509.       End
  510.       Begin Menu mnuFindSurname 
  511.          Caption         =   "Find &Surname"
  512.       End
  513.       Begin Menu mnuFindNext 
  514.          Caption         =   "Find &Next"
  515.       End
  516.       Begin Menu mnuFindDeleted 
  517.          Caption         =   "Find &Deleted"
  518.       End
  519.    End
  520.    Begin Menu mnuAbout 
  521.       Caption         =   "&About"
  522.       Begin Menu mnuAboutProject 
  523.          Caption         =   "&Project"
  524.       End
  525.       Begin Menu mnuAboutDataCraft 
  526.          Caption         =   "&DataCraft"
  527.       End
  528.    End
  529. Option Explicit
  530. Dim udtDataRecord       As udtRecord    ' Instance of User Defined Data Type
  531. Dim udtCopyRecord       As udtRecord    ' Instance of User Defined Data Type
  532. Dim flngPosition        As Long         ' flngPosition describes presentation order.
  533. Dim flngLastRecord      As Long         ' Last Record tracker
  534. Dim fstrFilename        As String
  535. Dim fintFilenumber      As Integer
  536. Dim findContinue        As Integer
  537. Dim fstrSearch          As String
  538. Sub CleanUpFile ()
  539.     Dim intClearNumber  As Integer
  540.     Dim lngLoop         As Long
  541.     Dim indConfirm      As Integer  'Boolean Indicator (ind...)
  542.     Exit Sub
  543.     If MsgBox("Would you like to recreate and remove duplicate records from the " & fstrFilename & " File?", 32 + 4, "Want Cleanup?") = 7 Then Exit Sub
  544.     indConfirm = False
  545.     Screen.MousePointer = 11
  546.     intClearNumber = FileOpener("~~Tmp~~.Tmp", RANDOMFILE, Len(udtDataRecord), indConfirm)
  547.     For lngLoop = 1 To flngLastRecord
  548.     Get #fintFilenumber, lngLoop, udtDataRecord
  549.     Put #intClearNumber, lngLoop, udtDataRecord
  550.     Next lngLoop
  551.     Close ' Close all files.
  552.     FileCopy "~~Tmp~~.Tmp", fstrFilename
  553.     fintFilenumber = FileOpener(fstrFilename, RANDOMFILE, Len(udtDataRecord), indConfirm)
  554.     Kill "~~Tmp~~.Tmp"
  555.     Screen.MousePointer = 0
  556. End Sub
  557. Sub cmdAbort_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  558.     findContinue = False
  559.     DoEvents
  560.     MsgBox "Aborted Random Data Generator", 48, "Random Data Generator Aborted"
  561. End Sub
  562. Sub cmdAddOption ()
  563.     Dim intLoop     As Integer
  564.     SaveRecordChanges
  565.     If flngLastRecord + 1 <= MAX_RECORDS Then
  566.     For intLoop = 0 To MAX_DATAFIELDS - 1
  567.         txtData(intLoop).Text = ""
  568.     Next intLoop
  569.     GetFields
  570.     flngLastRecord = flngLastRecord + 1
  571.     udtDataRecord.AccountNumber = flngLastRecord
  572.     Put #fintFilenumber, flngLastRecord, udtDataRecord
  573.     flngPosition = flngLastRecord
  574.     ShowRecord
  575.     Else
  576.     MsgBox "Maximum number of records reached in this file", 16, "File Full"
  577.     End If
  578. End Sub
  579. Sub cmdDeleteOption ()
  580.     Dim strMsg      As String
  581.     If flngLastRecord = 1 Then
  582.     strMsg = "This is the last record in the file. Deleting it will destroy"
  583.     strMsg = strMsg + " the whole file."
  584.     strMsg = strMsg + " Record Editor will also be closed."
  585.     strMsg = strMsg + " Choose OK to destroy file."
  586.     If MsgBox(strMsg, 65, "About to delete file!") = 1 Then
  587.         Close (fintFilenumber)
  588.         Kill fstrFilename
  589.         End
  590.     Else
  591.         Exit Sub
  592.     End If
  593.     End If
  594.     If MsgBox("Delete this record?", 32 + 4, "Delete Record") = 6 Then
  595.     flngPosition = Val(txtData(0).Text)
  596.     udtDataRecord.AccountNumber = flngPosition
  597.     udtDataRecord.Status = "D"
  598.     Put #fintFilenumber, flngPosition, udtDataRecord
  599.     ShowRecord
  600.     End If
  601. End Sub
  602. Sub cmdExitOption ()
  603.     SaveRecordChanges
  604.     CleanUpFile
  605.     End
  606. End Sub
  607. Sub cmdFindDeletedOption ()
  608.     On Error GoTo FindDeletedError
  609.     Dim lngRecordNumber     As Long
  610.     Dim strData             As String
  611.     Dim strTab              As String
  612.     Dim indFound            As Integer      ' Boolean Indicator (ind...)
  613.     strTab = Chr$(9)
  614.     SaveRecordChanges
  615.     fstrSearch = "D"
  616.     If fstrSearch > "" Then
  617.     Screen.MousePointer = 11
  618.     lstResults.Clear
  619.     For lngRecordNumber = 1 To flngLastRecord
  620.         Get #fintFilenumber, lngRecordNumber, udtDataRecord
  621.         If Trim$(udtDataRecord.Status) = "D" Then
  622.         strData = udtDataRecord.Surname & strTab
  623.         strData = strData & udtDataRecord.Forename & strTab
  624.         strData = strData & udtDataRecord.AccountNumber & strTab
  625.         lstResults.AddItem strData
  626.         indFound = True
  627.         End If
  628.     Next lngRecordNumber
  629.     Screen.MousePointer = 0
  630.     If indFound = False Then
  631.         MsgBox "Did not find any Deleted Records", 48, "Find Deleted Records"
  632.     End If
  633.     End If
  634. FindDeletedExit:
  635.     Exit Sub
  636. FindDeletedError:
  637.     Screen.MousePointer = 0
  638.     MsgBox "Error while finding Deleted Records: " & Error$, 48, "Find Error"
  639.     Resume FindDeletedExit
  640. End Sub
  641. Sub cmdFindNextOption ()
  642.     Dim lngRecordNumber     As Long
  643.     SaveRecordChanges
  644.     If fstrSearch > "" Then
  645.     Screen.MousePointer = 11
  646.     For lngRecordNumber = flngPosition + 1 To flngLastRecord
  647.         Get #fintFilenumber, lngRecordNumber, udtDataRecord
  648.         If InStr(1, udtDataRecord.Surname, fstrSearch, 1) > 0 Then
  649.         flngPosition = lngRecordNumber
  650.         Screen.MousePointer = 0
  651.         ShowRecord
  652.         SetFocusTo "Surname"
  653.         Exit Sub
  654.         End If
  655.     Next lngRecordNumber
  656.     Screen.MousePointer = 0
  657.     MsgBox "Did not find '" & fstrSearch & "'", 48
  658.     End If
  659. End Sub
  660. Sub cmdFindRecordOption ()
  661.     On Error GoTo FindRecordError
  662.     Dim lngRecordNumber     As Long
  663.     Dim strData             As String
  664.     SaveRecordChanges
  665.     strData = Trim$(InputBox$("Enter the Record Number to Find", "Find a record"))
  666.     If strData > "" Then
  667.     lngRecordNumber = Val(strData)
  668.     If lngRecordNumber >= 1 And lngRecordNumber <= flngLastRecord Then
  669.         flngPosition = lngRecordNumber
  670.         ShowRecord
  671.     Else
  672.         MsgBox lngRecordNumber & " is out of range of 1 and " & Str$(flngLastRecord), 48
  673.     End If
  674.     End If
  675. FindRecordExit:
  676.     Exit Sub
  677. FindRecordError:
  678.     MsgBox "Error while finding record: " & Error$, 48, "Find Error"
  679.     Resume FindRecordExit
  680. End Sub
  681. Sub cmdFindSurnameOption ()
  682.     On Error GoTo FindSurnameError
  683.     Dim lngRecordNumber     As Long
  684.     Dim strData             As String
  685.     Dim strTab              As String
  686.     Dim indFound            As Integer      ' Boolean Indicator (ind...)
  687.     strTab = Chr$(9)
  688.     SaveRecordChanges
  689.     fstrSearch = InputBox$("Enter the whole/part Surname to Find", "Find a record")
  690.     SetCommandEnabled "FindNext", fstrSearch > ""
  691.     If fstrSearch > "" Then
  692.     Screen.MousePointer = 11
  693.     lstResults.Clear
  694.     For lngRecordNumber = 1 To flngLastRecord
  695.         Get #fintFilenumber, lngRecordNumber, udtDataRecord
  696.         If InStr(1, udtDataRecord.Surname, fstrSearch, 1) > 0 Then
  697.         strData = udtDataRecord.Surname & strTab
  698.         strData = strData & udtDataRecord.Forename & strTab
  699.         strData = strData & udtDataRecord.AccountNumber & strTab
  700.         lstResults.AddItem strData
  701.         indFound = True
  702.         'flngPosition = lngRecordNumber
  703.         'Screen.MousePointer = 0
  704.         'ShowRecord
  705.         'SetFocusTo "Surname"
  706.         'Exit Sub
  707.         End If
  708.     Next lngRecordNumber
  709.     Screen.MousePointer = 0
  710.     If indFound = False Then
  711.         MsgBox "Did not find '" & fstrSearch & "'", 48
  712.     End If
  713.     End If
  714. FindSurnameExit:
  715.     Exit Sub
  716. FindSurnameError:
  717.     Screen.MousePointer = 0
  718.     MsgBox "Error while finding records: " & Error$, 48, "Find Error"
  719.     Resume FindSurnameExit
  720. End Sub
  721. Sub cmdJumbleOption ()
  722.     ' Please excuse the naf coding in this procedure
  723.     ' We have a Data Protection Act here in the UK that
  724.     ' Controls the storage of data about individuals
  725.     ' This procedure was quickly written to randomize the data
  726.     ' beyond all recognition and protect the guilty!
  727.     ' I left it intact in case if provoked some ideas for you
  728.     Dim lngOne      As Long
  729.     Dim lngTwo      As Long
  730.     Dim intLoop     As Integer
  731.     Dim strData     As String
  732.     Dim strCopy     As String
  733.     Dim strMsg      As String
  734.     Dim strField    As String
  735.     Dim strStore    As String
  736.     If findContinue = True Then Exit Sub
  737.     If MsgBox("WARNING!! THIS OPTION RANDOMLY SWAPS FIELD DATA FROM ONE RECORD TO ANOTHER AND COMPLETELY DESTROYS THE INTEGRETY OF YOUR DATABASE!!" & Chr$(13) & "DO  YOU WANT TO CONTINUE?", 16 + 4, "JUMBLE CURRENT DATABASE?") = 7 Then Exit Sub
  738.     strStore = cmdAbort.Caption
  739.     cmdAbort.Caption = "&Abort Data Jumble"
  740.     findContinue = True
  741.     cmdAbort.Visible = True
  742.     While findContinue = True
  743.     Randomize
  744.     lngTwo = Int((flngLastRecord - 1 + 1) * Rnd + 1)
  745.     flngPosition = lngTwo
  746.     ShowRecord
  747.     udtCopyRecord = udtDataRecord
  748.     lngOne = lngTwo
  749.     While lngOne = lngTwo
  750.         Randomize
  751.         lngOne = Int((flngLastRecord - 1 + 1) * Rnd + 1)
  752.     Wend
  753.     flngPosition = lngOne
  754.     ShowRecord
  755.     Randomize
  756.     intLoop = Int((10 - 1 + 1) * Rnd + 1)
  757.     Select Case intLoop
  758.         Case 1
  759.         strField = "Forename"
  760.         strData = Trim$(udtDataRecord.Forename)
  761.         strCopy = Trim$(udtCopyRecord.Forename)
  762.         If strData = "Test data" Then strData = "Raymond"
  763.         If strCopy = "Test data" Then strCopy = "Raymond"
  764.         udtDataRecord.Forename = strCopy
  765.         udtCopyRecord.Forename = strData
  766.         Case 2
  767.         strField = "Surname"
  768.         strData = Trim$(udtDataRecord.Surname)
  769.         strCopy = Trim$(udtCopyRecord.Surname)
  770.         If strData = "Test data" Then strData = "Wood"
  771.         If strCopy = "Test data" Then strCopy = "Wood"
  772.         udtDataRecord.Surname = strCopy
  773.         udtCopyRecord.Surname = strData
  774.         Case 3
  775.         strField = "Company"
  776.         strData = Trim$(udtDataRecord.Company)
  777.         strCopy = Trim$(udtCopyRecord.Company)
  778.         If strData = "Test data" Then strData = "DataCraft Development Company"
  779.         If strCopy = "Test data" Then strCopy = "DataCraft Development Company"
  780.         udtDataRecord.Company = strCopy
  781.         udtCopyRecord.Company = strData
  782.         Case 4
  783.         strField = "Address1"
  784.         strData = Trim$(udtDataRecord.Address1)
  785.         strCopy = Trim$(udtCopyRecord.Address1)
  786.         If strData = "Test data" Then strData = "42 John Gooch Drive"
  787.         If strCopy = "Test data" Then strCopy = "42 John Gooch Drive"
  788.         udtDataRecord.Address1 = strCopy
  789.         udtCopyRecord.Address1 = strData
  790.         Case 5
  791.         strField = "Address2"
  792.         strData = Trim$(udtDataRecord.Address2)
  793.         strCopy = Trim$(udtCopyRecord.Address2)
  794.         If strData = "Test data" Then strData = "Holtwhites Hill"
  795.         If strCopy = "Test data" Then strCopy = "Holtwhites Hill"
  796.         udtDataRecord.Address2 = strCopy
  797.         udtCopyRecord.Address2 = strData
  798.         Case 6
  799.         strField = "Address3"
  800.         strData = Trim$(udtDataRecord.Address3)
  801.         strCopy = Trim$(udtCopyRecord.Address3)
  802.         If strData = "Test data" Then strData = "Enfield"
  803.         If strCopy = "Test data" Then strCopy = "Enfield"
  804.         udtDataRecord.Address3 = strCopy
  805.         udtCopyRecord.Address3 = strData
  806.         Case 7
  807.         strField = "PostCode"
  808.         strData = Trim$(udtDataRecord.PostCode)
  809.         strCopy = Trim$(udtCopyRecord.PostCode)
  810.         If strData = "Test data" Then strData = "EN2 8HG"
  811.         If strCopy = "Test data" Then strCopy = "EN2 8HG"
  812.         udtDataRecord.PostCode = strCopy
  813.         udtCopyRecord.PostCode = strData
  814.         Case 8
  815.         strField = "Telephone"
  816.         strData = Trim$(udtDataRecord.Telephone)
  817.         strCopy = Trim$(udtCopyRecord.Telephone)
  818.         If strData = "Test data" Then strData = "0181 367 9278"
  819.         If strCopy = "Test data" Then strCopy = "0181 367 9278"
  820.         udtDataRecord.Telephone = strCopy
  821.         udtCopyRecord.Telephone = strData
  822.         Case 9
  823.         strField = "Fax"
  824.         strData = Trim$(udtDataRecord.Fax)
  825.         strCopy = Trim$(udtCopyRecord.Fax)
  826.         If strData = "Test data" Then strData = "0181 364 5278"
  827.         If strCopy = "Test data" Then strCopy = "0181 364 5278"
  828.         udtDataRecord.Fax = strCopy
  829.         udtCopyRecord.Fax = strData
  830.         Case 10
  831.         strField = "EMail"
  832.         strData = Trim$(udtDataRecord.EMail)
  833.         strCopy = Trim$(udtCopyRecord.EMail)
  834.         If strData = "Test data" Then strData = "100037,37"
  835.         If strCopy = "Test data" Then strCopy = "100037,37"
  836.         udtDataRecord.EMail = strCopy
  837.         udtCopyRecord.EMail = strData
  838.     End Select
  839.     strMsg = "Swapping " & strData & " to " & strCopy
  840.     Me.Caption = strMsg
  841.     flngPosition = lngOne
  842.     UpdateDisplay
  843.     SetFocusTo strField: DoEvents
  844.     SaveRecordChanges
  845.     flngPosition = lngTwo
  846.     udtDataRecord = udtCopyRecord
  847.     UpdateDisplay
  848.     SaveRecordChanges
  849.     Wend
  850.     cmdAbort.Visible = False
  851.     cmdAbort.Caption = strStore
  852.     findContinue = False
  853. End Sub
  854. Sub cmdMove_Click (Index As Integer)
  855.     Dim strMove     As String
  856.     Dim lngTemp     As Long
  857.     Dim strMsg      As String
  858.     strMove = cmdMove(Index).Tag
  859.     SaveRecordChanges
  860.     Select Case strMove
  861.     Case "First"
  862.         lngTemp = 1
  863.     Case "Previous"
  864.         lngTemp = flngPosition - 1
  865.     Case "Next"
  866.         lngTemp = flngPosition + 1
  867.     Case "Last"
  868.         lngTemp = flngLastRecord
  869.     End Select
  870.     If lngTemp < 1 Then
  871.     strMsg = "At beginning of file"
  872.     ElseIf lngTemp > flngLastRecord Then
  873.     strMsg = "At end of file"
  874.     ElseIf lngTemp >= 1 And lngTemp <= flngLastRecord Then
  875.     flngPosition = lngTemp
  876.     ShowRecord
  877.     End If
  878.     If strMsg > "" Then MsgBox strMsg, 48, "Record Navigation"
  879. End Sub
  880. Sub cmdOpenOption (TheDefault As String)
  881.     Dim indConfirm      As Integer  ' Boolean Indicator (ind...)
  882.     indConfirm = True
  883.     If flngLastRecord > 0 Then
  884.     SaveRecordChanges
  885.     CleanUpFile
  886.     End If
  887.     fintFilenumber = 0
  888.     Do While fintFilenumber = 0
  889.     fstrFilename = LCase$(GetFilename("Enter the name of a file to create or open" & Chr$(13) & Chr$(13) & "(an address.rnd file should be available in the current working directory)", TheDefault))
  890.     If fstrFilename = "" Then
  891.         End
  892.     Else
  893.         fintFilenumber = FileOpener(fstrFilename, RANDOMFILE, Len(udtDataRecord), indConfirm)
  894.         If fintFilenumber = 0 Then End
  895.     End If
  896.     Loop
  897.     Initialize
  898. End Sub
  899. Sub cmdOption_Click (Index As Integer)
  900.     Dim strOption       As String
  901.     strOption = cmdOption(Index).Tag
  902.     Select Case strOption
  903.     Case "Add"
  904.         cmdAddOption
  905.     Case "Delete"
  906.         cmdDeleteOption
  907.     Case "FindRecord"
  908.         cmdFindRecordOption
  909.     Case "FindString"
  910.         cmdFindSurnameOption
  911.     Case "FindNext"
  912.         cmdFindNextOption
  913.     Case "FindDeleted"
  914.         cmdFindDeletedOption
  915.     Case "Jumble"
  916.         cmdJumbleOption
  917.     Case "Open"
  918.         cmdOpenOption fstrFilename
  919.     Case "Save"
  920.         cmdSaveOption
  921.     Case "Exit"
  922.         cmdExitOption
  923.     Case "Random"
  924.         cmdRandomOption
  925.     End Select
  926. End Sub
  927. Sub cmdRandomOption ()
  928.     On Error GoTo RandomError
  929.     Dim lngLoop     As Long
  930.     Dim lngTotal    As Long
  931.     Dim lngCount    As Long
  932.     Dim strData     As String
  933.     Dim strFilename As String
  934.     Dim intChannel  As Integer
  935.     Dim lngAccountNumber   As Long
  936.     Dim strCompany         As String * 30
  937.     Dim strForename        As String * 12
  938.     Dim strSurname         As String * 12
  939.     Dim strAddress1        As String * 30
  940.     Dim strAddress2        As String * 30
  941.     Dim strAddress3        As String * 30
  942.     Dim strPostCode        As String * 15
  943.     Dim strTelephone       As String * 15
  944.     Dim strFax             As String * 15
  945.     Dim strEMail           As String * 15
  946.     Dim strStatus          As String * 1
  947.     If MsgBox("THIS OPTION WILL OVERWRITE ALL EXISTING DATA" & Chr$(13) & "DO YOU WANT TO CONTINUE?", 16 + 4, "WARNING!! THIS DELETES ALL CURRENT DATA!!") = 7 Then Exit Sub
  948.     strData = "This is test data for the automatic record generation procedure."
  949.     strData = strData & " We include fairly lenghty text in order to test the searching capabilities of the the instr function."
  950.     strData = strData & " There must be a better way of locating records when using random access files in Visual Basic. "
  951.     strData = "This is test data for the automatic record generation procedure for record number: "
  952.     lngTotal = Val(InputBox$("Enter the number of records to generate (between 1 and  2,147,483,647)", "Number to Generate", "1000"))
  953.     If lngTotal >= 1 And lngTotal <= MAX_RECORDS Then
  954.     findContinue = True
  955.     cmdAbort.Visible = True
  956.     chkSave.Value = False
  957.     intChannel = FreeFile
  958.     strFilename = App.Path & "\random.txt"
  959.     Open strFilename For Input As intChannel
  960.     While lngCount < lngTotal And Err = 0 And findContinue = True And EOF(intChannel) = False
  961.         lngCount = lngCount + 1
  962.         Line Input #intChannel, strData
  963.         lngAccountNumber = Val(strData)
  964.         Line Input #intChannel, strStatus
  965.         Line Input #intChannel, strForename
  966.         Line Input #intChannel, strSurname
  967.         Line Input #intChannel, strCompany
  968.         Line Input #intChannel, strAddress1
  969.         Line Input #intChannel, strAddress2
  970.         Line Input #intChannel, strAddress3
  971.         Line Input #intChannel, strPostCode
  972.         Line Input #intChannel, strTelephone
  973.         Line Input #intChannel, strFax
  974.         Line Input #intChannel, strEMail
  975.         SetDataFor "AccountNumber", lngAccountNumber
  976.         SetDataFor "Status", Trim$(strStatus)
  977.         SetDataFor "Forename", Trim$(strForename)
  978.         SetDataFor "Surname", Trim$(strSurname)
  979.         SetDataFor "Company", Trim$(strCompany)
  980.         SetDataFor "Address1", Trim$(strAddress1)
  981.         SetDataFor "Address2", Trim$(strAddress2)
  982.         SetDataFor "Address3", Trim$(strAddress3)
  983.         SetDataFor "PostCode", Trim$(strPostCode)
  984.         SetDataFor "Telephone", Trim$(strTelephone)
  985.         SetDataFor "Fax", Trim$(strFax)
  986.         SetDataFor "EMail", Trim$(strEMail)
  987.         
  988.         flngLastRecord = lngAccountNumber
  989.         flngPosition = lngAccountNumber
  990.         SaveRecordChanges
  991.         DoEvents
  992.     Wend
  993.     End If
  994. RandomExit:
  995.     cmdAbort.Visible = False
  996.     Close #intChannel
  997.     findContinue = False
  998.     Exit Sub
  999. RandomError:
  1000.     MsgBox "Error while generating random records from file '" & strFilename & "' : " & Error$, 48, "Random Error"
  1001.     Resume RandomExit
  1002. End Sub
  1003. Sub cmdSaveOption ()
  1004.     SaveRecordChanges
  1005. End Sub
  1006. Sub Form_Load ()
  1007.     ReDim arrTabs(1)    As Integer
  1008.     Dim lngResult       As Long
  1009.     Me.Move ((Screen.Width - Me.Width) / 2), ((Screen.Height - Me.Height) / 2)
  1010.     ChDrive App.Path
  1011.     ChDir App.Path
  1012.     Me.Show
  1013.     arrTabs(0) = 60
  1014.     arrTabs(1) = 500
  1015.     lngResult = SendMessage(lstResults.hWnd, LB_SETTABSTOPS, 2, arrTabs(0))
  1016.     cmdOpenOption "address.rnd"
  1017. End Sub
  1018. Sub Form_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  1019.     On Error GoTo WriteError
  1020.     Dim strFilename     As String
  1021.     Dim intChannel      As Integer
  1022.     Dim lngLoop         As Long
  1023.     If Button = 2 Then
  1024.     Screen.MousePointer = 11
  1025.     strFilename = App.Path & "\address.asc"
  1026.     intChannel = FreeFile
  1027.     Open strFilename For Output As intChannel
  1028.     For lngLoop = 1 To flngLastRecord
  1029.         Get #fintFilenumber, lngLoop, udtDataRecord
  1030.         Print #intChannel, Trim$(Str$(udtDataRecord.AccountNumber))
  1031.         Print #intChannel, Trim$(udtDataRecord.Status)
  1032.         Print #intChannel, Trim$(udtDataRecord.Forename)
  1033.         Print #intChannel, Trim$(udtDataRecord.Surname)
  1034.         Print #intChannel, Trim$(udtDataRecord.Company)
  1035.         Print #intChannel, Trim$(udtDataRecord.Address1)
  1036.         Print #intChannel, Trim$(udtDataRecord.Address2)
  1037.         Print #intChannel, Trim$(udtDataRecord.Address3)
  1038.         Print #intChannel, Trim$(udtDataRecord.PostCode)
  1039.         Print #intChannel, Trim$(udtDataRecord.Telephone)
  1040.         Print #intChannel, Trim$(udtDataRecord.Fax)
  1041.         Print #intChannel, Trim$(udtDataRecord.EMail)
  1042.     Next lngLoop
  1043.     End If
  1044.     Screen.MousePointer = 0
  1045. WriteExit:
  1046.     Close #intChannel
  1047.     Exit Sub
  1048. WriteError:
  1049.     Screen.MousePointer = 0
  1050.     MsgBox "Error while writing records: " & Error$, 48, "Write Error"
  1051.     Resume WriteExit
  1052. End Sub
  1053. Sub Form_Unload (Cancel As Integer)
  1054.     End
  1055. End Sub
  1056. Function GetDataFor (TheField As String, TheDataType) As Variant
  1057.     Dim intLoop     As Integer
  1058.     For intLoop = 0 To Controls.Count - 1
  1059.     If TypeOf Controls(intLoop) Is TextBox Then
  1060.         If Controls(intLoop).Tag = TheField Then
  1061.         Select Case TheDataType
  1062.             Case "Numeric"
  1063.             GetDataFor = Val(Controls(intLoop).Text)
  1064.             Case "Text"
  1065.             GetDataFor = Trim$(Controls(intLoop).Text)
  1066.         End Select
  1067.         Exit For
  1068.         End If
  1069.     End If
  1070.     Next intLoop
  1071. End Function
  1072. Sub GetFields ()
  1073.     'Transfer the data from the textboxes into the data record
  1074.     udtDataRecord.AccountNumber = GetDataFor("AccountNumber", "Numeric")
  1075.     udtDataRecord.Status = GetDataFor("Status", "Text")
  1076.     udtDataRecord.Forename = GetDataFor("Forename", "Text")
  1077.     udtDataRecord.Surname = GetDataFor("Surname", "Text")
  1078.     udtDataRecord.Company = GetDataFor("Company", "Text")
  1079.     udtDataRecord.Address1 = GetDataFor("Address1", "Text")
  1080.     udtDataRecord.Address2 = GetDataFor("Address2", "Text")
  1081.     udtDataRecord.Address3 = GetDataFor("Address3", "Text")
  1082.     udtDataRecord.PostCode = GetDataFor("PostCode", "Text")
  1083.     udtDataRecord.Telephone = GetDataFor("Telephone", "Text")
  1084.     udtDataRecord.Fax = GetDataFor("Fax", "Text")
  1085.     udtDataRecord.EMail = GetDataFor("EMail", "Text")
  1086. End Sub
  1087. Sub Initialize ()
  1088.     flngLastRecord = LOF(fintFilenumber) \ Len(udtDataRecord)
  1089.     flngPosition = 1
  1090.     If flngLastRecord < 1 Then
  1091.     GetFields
  1092.     cmdAddOption
  1093.     Else
  1094.     ShowRecord
  1095.     End If
  1096. End Sub
  1097. Sub lstResults_Click ()
  1098.     Dim strData     As String
  1099.     If lstResults.ListIndex > -1 Then
  1100.     SaveRecordChanges
  1101.     strData = lstResults.List(lstResults.ListIndex)
  1102.     strData = ExtractElement(strData, 2)
  1103.     flngPosition = Val(Trim$(strData))
  1104.     ShowRecord
  1105.     SetFocusTo "Surname"
  1106.     End If
  1107. End Sub
  1108. Sub mnuAboutDataCraft_Click ()
  1109.     frmAbout.Show 1
  1110.     Me.Refresh
  1111.     DoEvents
  1112. End Sub
  1113. Sub mnuAboutProject_Click ()
  1114.     frmHelp.Show 1
  1115.     Me.Refresh
  1116.     DoEvents
  1117. End Sub
  1118. Sub mnuEditAdd_Click ()
  1119.     cmdAddOption
  1120. End Sub
  1121. Sub mnuEditDelete_Click ()
  1122.     cmdDeleteOption
  1123. End Sub
  1124. Sub mnuEditJumble_Click ()
  1125.     cmdJumbleOption
  1126. End Sub
  1127. Sub mnuEditSave_Click ()
  1128.     cmdSaveOption
  1129. End Sub
  1130. Sub mnuFileExit_Click ()
  1131.     cmdExitOption
  1132. End Sub
  1133. Sub mnuFileOpen_Click ()
  1134.     cmdOpenOption "address.rnd"
  1135. End Sub
  1136. Sub mnuFindDeleted_Click ()
  1137.     cmdFindDeletedOption
  1138. End Sub
  1139. Sub mnuFindNext_Click ()
  1140.     cmdFindNextOption
  1141. End Sub
  1142. Sub mnuFindRecord_Click ()
  1143.     cmdFindRecordOption
  1144. End Sub
  1145. Sub mnuFindSurname_Click ()
  1146.     cmdFindSurnameOption
  1147. End Sub
  1148. Sub OpenFile_Click ()
  1149. End Sub
  1150. Sub ResetTextBoxes ()
  1151.     Dim intLoop     As Integer
  1152.     For intLoop = 0 To Controls.Count - 1
  1153.     If TypeOf Controls(intLoop) Is TextBox Then
  1154.         If Controls(intLoop).Tag > "" Then
  1155.         Controls(intLoop).DataChanged = False
  1156.         End If
  1157.     End If
  1158.     Next intLoop
  1159. End Sub
  1160. Sub SaveRecordChanges ()
  1161.     On Error GoTo SaveError
  1162.     Dim indChanged  As Integer  'Boolean Indicator (ind...)
  1163.     Dim intLoop     As Integer
  1164.     For intLoop = 0 To Controls.Count - 1
  1165.     If TypeOf Controls(intLoop) Is TextBox Then
  1166.         If Controls(intLoop).Tag > "" Then
  1167.         If Controls(intLoop).DataChanged = True Then
  1168.             indChanged = True
  1169.             Exit For
  1170.         End If
  1171.         End If
  1172.     End If
  1173.     Next intLoop
  1174.     If indChanged = True Then
  1175.     GetFields
  1176.     Put #fintFilenumber, flngPosition, udtDataRecord
  1177.     If Err = 0 And chkSave.Value = True Then
  1178.         MsgBox "Saved record " & udtDataRecord.AccountNumber & " OK", 48, "Saved Record"
  1179.         ResetTextBoxes
  1180.     End If
  1181.     End If
  1182. SaveExit:
  1183.     Exit Sub
  1184. SaveError:
  1185.     MsgBox "Error while saving record: " & Error$, 48, "Save Error"
  1186.     Resume SaveExit
  1187. End Sub
  1188. Sub SetCommandEnabled (TheField As String, TheMode As Integer)
  1189.     Dim intLoop     As Integer
  1190.     For intLoop = 0 To Controls.Count - 1
  1191.     If TypeOf Controls(intLoop) Is CommandButton Then
  1192.         If Controls(intLoop).Tag = TheField Then
  1193.         Controls(intLoop).Enabled = TheMode
  1194.         Exit Sub
  1195.         End If
  1196.     End If
  1197.     Next intLoop
  1198.     MsgBox "Unable to locate Command Button '" & TheField & "'", 48, "Internal Error"
  1199. End Sub
  1200. Sub SetDataFor (TheField As String, TheData As Variant)
  1201.     Dim intLoop     As Integer
  1202.     For intLoop = 0 To Controls.Count - 1
  1203.     If TypeOf Controls(intLoop) Is TextBox Then
  1204.         If Controls(intLoop).Tag = TheField Then
  1205.         Controls(intLoop).Text = TheData
  1206.         Exit For
  1207.         End If
  1208.     End If
  1209.     Next intLoop
  1210. End Sub
  1211. Sub SetFocusTo (TheField As String)
  1212.     Dim intLoop     As Integer
  1213.     For intLoop = 0 To Controls.Count - 1
  1214.     If TypeOf Controls(intLoop) Is TextBox Then
  1215.         If Controls(intLoop).Tag = TheField Then
  1216.         Controls(intLoop).SetFocus
  1217.         Exit For
  1218.         End If
  1219.     End If
  1220.     Next intLoop
  1221. End Sub
  1222. Sub ShowRecord ()
  1223.     Get #fintFilenumber, flngPosition, udtDataRecord
  1224.     'Transfer the data from the data record to the textboxes
  1225.     SetDataFor "AccountNumber", udtDataRecord.AccountNumber
  1226.     SetDataFor "Status", Trim$(udtDataRecord.Status)
  1227.     SetDataFor "Forename", Trim$(udtDataRecord.Forename)
  1228.     SetDataFor "Surname", Trim$(udtDataRecord.Surname)
  1229.     SetDataFor "Company", Trim$(udtDataRecord.Company)
  1230.     SetDataFor "Address1", Trim$(udtDataRecord.Address1)
  1231.     SetDataFor "Address2", Trim$(udtDataRecord.Address2)
  1232.     SetDataFor "Address3", Trim$(udtDataRecord.Address3)
  1233.     SetDataFor "PostCode", Trim$(udtDataRecord.PostCode)
  1234.     SetDataFor "Telephone", Trim$(udtDataRecord.Telephone)
  1235.     SetDataFor "Fax", Trim$(udtDataRecord.Fax)
  1236.     SetDataFor "EMail", Trim$(udtDataRecord.EMail)
  1237.     If Trim$(udtDataRecord.Status) = "D" Then
  1238.     lblDeleted.Visible = True
  1239.     Else
  1240.     lblDeleted.Visible = False
  1241.     End If
  1242.     lblDeleted.Refresh
  1243.     DoEvents
  1244.     ResetTextBoxes
  1245.     GetFields
  1246.     UpdateCaption
  1247.     SetFocusTo "Company"
  1248. End Sub
  1249. Sub txtData_Change (Index As Integer)
  1250.     Dim strField        As String
  1251.     strField = txtData(Index).Tag
  1252.     Select Case strField
  1253.     Case "Status"
  1254.         If txtData(Index).Text = "D" Then
  1255.         lblDeleted.Visible = True
  1256.         Else
  1257.         lblDeleted.Visible = False
  1258.         End If
  1259.     End Select
  1260. End Sub
  1261. Sub txtData_GotFocus (Index As Integer)
  1262.     Dim strField        As String
  1263.     strField = txtData(Index).Tag
  1264.     Select Case strField
  1265.     Case "AccountNumber"
  1266.         SendKeys "{Tab}"    'don't allow access to record number!
  1267.     Case Else
  1268.         txtData(Index).BackColor = YELLOW
  1269.     End Select
  1270. End Sub
  1271. Sub txtData_KeyDown (Index As Integer, KeyCode As Integer, Shift As Integer)
  1272.     Const KEY_RETURN = &HD
  1273.     Const KEY_UP = &H26
  1274.     Const KEY_DOWN = &H28
  1275.     Select Case KeyCode
  1276.     Case KEY_DOWN, KEY_RETURN
  1277.         KeyCode = 0
  1278.         SendKeys "{Tab}"
  1279.     Case KEY_UP
  1280.         KeyCode = 0
  1281.         SendKeys "+{Tab}"
  1282.     End Select
  1283. End Sub
  1284. Sub txtData_KeyPress (Index As Integer, KeyAscii As Integer)
  1285.     Dim strField        As String
  1286.     If KeyAscii = 13 Then
  1287.     KeyAscii = 0
  1288.     Else
  1289.     strField = txtData(Index).Tag
  1290.     Select Case strField
  1291.         Case "PostCode"
  1292.         KeyAscii = Asc(UCase$(Chr$((KeyAscii))))
  1293.     End Select
  1294.     End If
  1295. End Sub
  1296. Sub txtData_LostFocus (Index As Integer)
  1297.     txtData(Index).BackColor = WHITE
  1298. End Sub
  1299. Sub UpdateCaption ()
  1300.     Dim strCaption         As String
  1301.     strCaption = fstrFilename & ": Record " & Str$(flngPosition)
  1302.     strCaption = strCaption & " of " & Str$(flngLastRecord)
  1303.     Me.Caption = strCaption
  1304. End Sub
  1305. Sub UpdateDisplay ()
  1306.     SetDataFor "AccountNumber", udtDataRecord.AccountNumber
  1307.     SetDataFor "Status", Trim$(udtDataRecord.Status)
  1308.     SetDataFor "Forename", Trim$(udtDataRecord.Forename)
  1309.     SetDataFor "Surname", Trim$(udtDataRecord.Surname)
  1310.     SetDataFor "Company", Trim$(udtDataRecord.Company)
  1311.     SetDataFor "Address1", Trim$(udtDataRecord.Address1)
  1312.     SetDataFor "Address2", Trim$(udtDataRecord.Address2)
  1313.     SetDataFor "Address3", Trim$(udtDataRecord.Address3)
  1314.     SetDataFor "PostCode", Trim$(udtDataRecord.PostCode)
  1315.     SetDataFor "Telephone", Trim$(udtDataRecord.Telephone)
  1316.     SetDataFor "Fax", Trim$(udtDataRecord.Fax)
  1317.     SetDataFor "EMail", Trim$(udtDataRecord.EMail)
  1318. End Sub
  1319.